#include("../../comm/ListHead.html")
<div class="layui-fluid layui-anim layui-anim-scale">
    <div class="layui-row layui-col-space5">
        <input type="hidden" id="type_code" value="#(form.key)"/>

        <div class="layui-col-md12 height-auto">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-hide" id="table_1" lay-filter="table_1"></table>

                    <script type="text/html" id="TplShow">
                        <input type="checkbox" field="is_show" msg="设置有效" value="{{d.d_id}}" lay-skin="primary"
                               lay-filter="ChangeTag" {{ d.is_show ? 'checked' : '' }}>
                    </script>
                    <script type="text/html" id="table_1_bar_title">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="AddSystemTypeDetail">
                                <i class="layui-icon">&#xe608;</i> 添加子分类
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="DelSystemTypeDetail">删除</button>
                            <button class="layui-btn layui-btn-sm btn-close" lay-event="CloseWindow">关闭</button>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script language="JavaScript">

    layui.use(['myTable', 'table', 'form', 'myTool'], function () {
        table = layui.table;
        form = layui.form;
        myTable = layui.myTable;
        var $ = layui.$;

        tableindex = myTable.render({
            elem: '#table_1', skin: 'line'
            , height: 390
            , url: 'SystemTypeDetailDataApi'
            , toolbar: '#table_1_bar_title'
            , title: '系统分类明细表'
            , where: {type_code: $("#type_code").val()}
            , cols: [[
                {type: 'checkbox', width: 36}
                , {field: 'd_id', title: '分类ID', width: 80, align: 'center', hide: true}
                , {field: 'sindex', title: '顺序', width: 80, align: 'center', edit: 'text'}
                , {field: 'd_key', title: '健KEY', width: 200, edit: 'text'}
                , {field: 'd_name', title: '健值', width: 200, edit: 'text'}
                , {field: 'd_desc', title: '备注说明', hide: false, edit: 'text'}
                , {title: '有效', width: 60, align: 'center', templet: '#TplShow'}
            ]]
            , page: true
            , limit: 5
            , editField: {url: 'ModifySystemTypeDetailFieldApi', key: 'd_id'}
        });

        //头工具栏事件
        table.on('toolbar(table_1)', function (obj) {
            layui.myTool.toolbar(this, obj, {
                AddSystemTypeDetail: function () {
                    index = layer.confirm('你是否确认添加新的子分类', {icon: 3, title: '提示', offset: '100px'}, function (index2) {
                        layer.close(index2);
                        $.get("AddSystemTypeDetailApi", {type_code: $("#type_code").val()}, function success() {
                            tableindex.reload();
                        })
                    });

                }
                , DelSystemTypeDetail: function () {
                    layui.myTool.doSingleSelect(table.checkStatus('table_1'), {}, function (data, keys) {
                        index = layer.confirm('你是否确认删除该子分类【' + data[0].d_name + '】', {icon: 3, title: '提示', offset: '100px'}, function (index2) {
                            layer.close(index2);
                            layui.myTool.post("DelSystemTypeDetailApi", {d_id: data[0].d_id}, function success() {
                                tableindex.reload();
                            })
                        });
                    });
                }

            });
        });
        form.on('checkbox(ChangeTag)', function (obj) {
            layui.myTool.postMsg("ChangeSysTypeDetailApi", {d_id: this.value, field: $(obj.elem).attr("field"), msg: $(obj.elem).attr("msg")}, function (result) {
                layui.layer.tips(result.msg, obj.othis);
            });
        });
    });
</script>
</body>
</html>


